package com.fund.product.listener;

import com.fund.product.pojo.entity.NetWorth;
import com.fund.product.service.NetWorthService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class WorthUpdateListener {

    @Autowired
    NetWorthService netWorthService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "product.worth.update.queue",durable = "true"),
            exchange = @Exchange(name = "worth.direct"),
            key = "worth.update"
    ))
    public void saveNewWorth(List<NetWorth> netWorthList) {
        netWorthService.saveBatch(netWorthList);
    }
}
